//
//  EmojTextAttachment.m
//  SinaWebo
//
//  Created by wwj on 16/5/19.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "EmojTextAttachment.h"
#import <SDWebImageManager.h>

@implementation EmojTextAttachment
+(instancetype)emojTextAttachment:(EmotionModel *)emotion font:(UIFont *)font{
    EmojTextAttachment *attach = [[EmojTextAttachment alloc] init];
    attach.image = [UIImage imageNamed:emotion.emtionPath];
    attach.bounds = CGRectMake(0, -4, font.lineHeight, font.lineHeight);
    attach.chs = emotion.chs;
    return attach;
}

+(instancetype)emojTextAttachmentWithImageName:(NSString *)imageName font:(UIFont *)font{
    EmojTextAttachment *attach = [[EmojTextAttachment alloc] init];
    attach.image = [UIImage imageNamed:imageName];
    attach.bounds = CGRectMake(0, -3, font.lineHeight, font.lineHeight);
    return attach;
}

+(instancetype)emojTextAttachmentWithImage:(UIImage *)image font:(UIFont *)font{
    EmojTextAttachment *attach = [[EmojTextAttachment alloc] init];
    attach.image = image;
    attach.bounds = CGRectMake(0, -3, font.lineHeight, font.lineHeight);
    return attach;
}

+(instancetype)emojTextAttachmentWithURL:(NSString *)url font:(UIFont *)font{
    EmojTextAttachment *attach = [[EmojTextAttachment alloc] init];
    attach.image = [UIImage imageNamed:@"tour"];
    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:url] options:SDWebImageRetryFailed progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        if (finished) {
            attach.image = image;
        }
    }];
    
    attach.bounds = CGRectMake(0, -3, font.lineHeight, font.lineHeight);
    return attach;
}
@end
